package com.yl.chainStore.entity.warehouse

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.enums.Status
import com.yl.chainStore.common.enums.TypeEnum
import com.yl.chainStore.util.GenerateNum
import com.yl.common.annotation.NoArg
import com.yl.common.getContext
import java.util.*

/**
 * <p>
 * 入库单
 * </p>
 *
 * @author cxw
 * @since 2021-06-10
 */
@NoArg
@TableName("warehouse_in_order")
data class WarehouseInOrder(

	/**
	 * 入库单
	 */
	@TableId(value = "id", type = IdType.AUTO)
	var id: Long,

	/**
	 * 仓库id
	 */
	@TableField("dept_id")
	val deptId: Long = getContext().subCompanyId,

	/**
	 * 公司id
	 */
	@TableField("company_id")
	val companyId: Long = getContext().companyId,

	/**
	 * 创建时间
	 */
	@TableField("create_time")
	val createTime: Date = Date(),

	/**
	 * 单据日期
	 */
	@TableField("order_time")
	var orderTime: Date? = Date(),

	/**
	 * 创建人
	 */
	@TableField("create_user_id")
	val createUserId: Long = getContext().userId,

	/**
	 * 类型
	 */
	@TableField("type")
	var type: TypeEnum = TypeEnum.OTHER,

	/**
	 * 供应商id
	 */
	@TableField("supplier_id")
	var supplierId: Long? = null,


	/**
	 * 入库人(操作人员)
	 */
	@TableField("in_user_id")
	var inUserId: Long? = null,

	@TableField(exist = false)
	var inUserName: String? = null,

	/**
	 * 审核人
	 */
	@TableField("deal_user_id")
	var dealUserId: Long? = null,

	@TableField(exist = false)
	var dealUserName: String? = null,

	/**
	 * 审核时间
	 */
	@TableField("deal_time")
	var dealTime: Date? = null,

	/**
	 * 数据有效性
	 */
	@TableField("enabled")
	var enabled: Int = 1,


	/**
	 * 状态
	 */
	@TableField("status")
	var status: Status = Status.UNKNOWN,


	/**
	 * 入库单号
	 */
	@TableField("in_order_num")
	val inOrderNum: String? = generateOrder("I"),

	/**
	 * 退领入库、入库部门
	 */
	@TableField("in_warehouse_dept_id")
	var inWarehouseDeptId: Long? = null,

	/**
	 * 退领入库、入库员工
	 */
	@TableField("in_warehouse_user_id")
	var inWarehouseUserId: Long? = null,

	@TableField(exist = false)
	var details: List<WarehouseInOrderDetail>? = null,

	@TableField("other")
	var other: String? = null,


	/**
	 * 入库关联对象id
	 */
	@TableField(exist = false)
	var inTypeObjectId: Long? = null,
){
	companion object : GenerateNum()

	@TableField(exist = false)
	var supplierName: String? = null

	@TableField(exist = false)
	var inWarehouseDeptName: String? = null

	@TableField(exist = false)
	var inWarehouseUserName: String? = null


	val inName: String?
		get() {
			return when (type) {
				TypeEnum.WAREHOUSE_IN_TYPE_SUPPLIER -> supplierName

				TypeEnum.WAREHOUSE_IN_TYPE_DEPT -> inWarehouseDeptName

				TypeEnum.WAREHOUSE_IN_TYPE_USER -> inWarehouseUserName
				else -> ""
			}
		}

	val orderIsSelf: Boolean
		get() {
			return createUserId == getContext().userId
		}

}
